package com.java110.mall.goods.bmo.productServKeyword.impl;

import com.java110.mall.goods.bmo.productServKeyword.IGetProductServKeywordBMO;
import com.java110.intf.goods.IProductServKeywordInnerServiceSMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.java110.dto.product.ProductServKeywordDto;

import java.util.ArrayList;
import java.util.List;

@Service("getProductServKeywordBMOImpl")
public class GetProductServKeywordBMOImpl implements IGetProductServKeywordBMO {

    @Autowired
    private IProductServKeywordInnerServiceSMO productServKeywordInnerServiceSMOImpl;

    /**
     *
     *
     * @param  productServKeywordDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(ProductServKeywordDto productServKeywordDto) {


        int count = productServKeywordInnerServiceSMOImpl.queryProductServKeywordsCount(productServKeywordDto);

        List<ProductServKeywordDto> productServKeywordDtos = null;
        if (count > 0) {
            productServKeywordDtos = productServKeywordInnerServiceSMOImpl.queryProductServKeywords(productServKeywordDto);
        } else {
            productServKeywordDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) productServKeywordDto.getRow()), count, productServKeywordDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
